package com.beone.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.beone.admin.entity.TaskAttachment;
import com.beone.admin.mapper.TaskAttachmentMapper;
import com.beone.admin.service.TaskAttachmentService;
import com.base.SuperServiceImpl;
import org.springframework.stereotype.Service;
import com.beone.admin.utils.PaginationGatagridTable;
import com.beone.admin.utils.ServiceUtils;

import java.util.List;

/**
 * @Title 任务附件表 服务实现类
 * @Author 秦波
 * @Version 1.0 on 2019-05-18
 * @Copyright 贝旺科权
 */
@Service
public class TaskAttachmentServiceImpl extends SuperServiceImpl<TaskAttachmentMapper, TaskAttachment> implements TaskAttachmentService {

    /**
    * 分页显示任务附件表列表
    * @param entity
    * @param currPage  当前页码
    * @param pageSize  每页显示记录数
    * @return
    */
    public PaginationGatagridTable getTaskAttachmentPagination(TaskAttachment entity, int currPage, int pageSize){
        EntityWrapper<TaskAttachment> ew = new EntityWrapper<TaskAttachment>();
        Page<TaskAttachment> page = new Page<TaskAttachment>(currPage,pageSize);
        List<TaskAttachment> rows = baseMapper.selectPage(page, ew);
        return ServiceUtils.createGatagridTableJson(page,rows);
    }

    @Override
    public boolean deleteByTaskId(Integer taskId) {
        Wrapper<TaskAttachment> wrapper = new EntityWrapper<>();
        wrapper.eq("task_id", taskId);
        return baseMapper.delete(wrapper) > 0;
    }

    @Override
    public List<TaskAttachment> selectListByTaskId(Integer taskId) {
        Wrapper<TaskAttachment> wrapper = new EntityWrapper<>();
        wrapper.eq("task_id", taskId);
        return baseMapper.selectList(wrapper);
    }
}
